//
//  NMPOFuncViewController.swift
//  NMPO
//
//  Created by PowerfullClean on 2023/10/31.
//

import UIKit

class NMPOFuncViewController: NMPOBaseCollectionViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }
    // MARK: - nmpo action
    override func nmpo_layout() -> UICollectionViewFlowLayout {
        let nmpo_layout = UICollectionViewFlowLayout()
        
        nmpo_layout.minimumLineSpacing = 10
        nmpo_layout.minimumInteritemSpacing = 20
        return nmpo_layout
    }
    override func nmpo_collectionViews() {
        super.nmpo_collectionViews()
        view.addSubview(nmpo_navView)
        nmpo_collectionView.snp.makeConstraints { make in
            make.bottom.width.left.equalToSuperview()
            make.top.equalTo(nmpo_navView.snp.bottom)
        }
        nmpo_collectionView.contentInset = UIEdgeInsets(top: 0, left: 20, bottom: NMPOCommon.nmpo_tabbarH+15, right: 20)
        nmpo_collectionView.register(NMPOFuncChooseCell.classForCoder(), forCellWithReuseIdentifier: NMPOFuncChooseCell.nmpo_viewToString)
        nmpo_collectionView.register(NMPOFuncMainFunCell.classForCoder(), forCellWithReuseIdentifier: NMPOFuncMainFunCell.nmpo_viewToString)
        nmpo_collectionView.register(NMPOFuncIpCell.classForCoder(), forCellWithReuseIdentifier: NMPOFuncIpCell.nmpo_viewToString)
        nmpo_collectionView.dataSource = self
        nmpo_collectionView.delegate = self
        
    }
    // MARK: - lazy
    override func nmpo_baseBgName() -> String? {
        return "nmpo_func_bg"
    }
    lazy var nmpo_navView: NMPOHomeNavView = {
        let nmpo_navView = NMPOHomeNavView()
        return nmpo_navView
    }()
    lazy var nmpo_funcMainModels: [NMPOFuncMainModel] = {
        var nmpo_funcMainModels = [NMPOFuncMainModel]()
        nmpo_funcMainModels.append(NMPOFuncMainModel(nmpo_type: .nmpo_choose))
        nmpo_funcMainModels.append(NMPOFuncMainModel(nmpo_type: .nmpo_func))
        nmpo_funcMainModels.append(NMPOFuncMainModel(nmpo_type: .nmpo_ipIfo))
        return nmpo_funcMainModels
    }()

}
// MARK: - lazy UICollectionViewDataSource UICollectionViewDelegateFlowLayout
extension NMPOFuncViewController: UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return nmpo_funcMainModels.count
    }
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let nmpo_funcMainModel = nmpo_funcMainModels[indexPath.row]
        if nmpo_funcMainModel.nmpo_type == .nmpo_func {
            let nmpo_cell = collectionView.dequeueReusableCell(withReuseIdentifier: NMPOFuncMainFunCell.nmpo_viewToString, for: indexPath) as! NMPOFuncMainFunCell
            return nmpo_cell
        }
        if nmpo_funcMainModel.nmpo_type == .nmpo_ipIfo {
            let nmpo_cell = collectionView.dequeueReusableCell(withReuseIdentifier: NMPOFuncIpCell.nmpo_viewToString, for: indexPath) as! NMPOFuncIpCell
            return nmpo_cell
        }
        let nmpo_cell = collectionView.dequeueReusableCell(withReuseIdentifier: NMPOFuncChooseCell.nmpo_viewToString, for: indexPath) as! NMPOFuncChooseCell
        return nmpo_cell
    }
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        let nmpo_funcMainModel = nmpo_funcMainModels[indexPath.row]
        if nmpo_funcMainModel.nmpo_type == .nmpo_choose {
            return CGSize(width: nmpo_SCREEN_WIDTH-40, height: 74)
        }
        if nmpo_funcMainModel.nmpo_type == .nmpo_func {
            return CGSize(width: nmpo_SCREEN_WIDTH-40, height: 112)
        }
        return CGSize(width: nmpo_SCREEN_WIDTH-40, height: 142)
    }
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        let nmpo_funcMainModel = nmpo_funcMainModels[indexPath.row]
        if nmpo_funcMainModel.nmpo_type == .nmpo_choose {
            navigationController?.pushViewController(NMPOSersListViewController(), animated: true)
        }
        if nmpo_funcMainModel.nmpo_type == .nmpo_ipIfo {
            navigationController?.pushViewController(NMPOScanViewController(nmpo_funcType: .nmpo_ip), animated: true)
        }
    }
}
